package com.xzx.source;

import org.apache.flink.streaming.api.functions.source.SourceFunction;

import java.util.Random;

/**
 * @author xinzhixuan
 * @version 1.0
 * @date 2024/3/3 09:43
 */
public class RandomNumSource implements SourceFunction<Integer> {
    private boolean running = true;

    @Override
    public void run(SourceContext<Integer> ctx) throws Exception {
        while (true) {
            ctx.collect(new Random().nextInt(10));
            Thread.sleep(1000L);
        }
    }

    @Override
    public void cancel() {
        running = false;
    }
}
